package com.engineering.elink.util.auth.phone;

import com.aliyun.mns.common.ClientException;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.sms.model.v20160927.SingleSendSmsRequest;
import com.aliyuncs.sms.model.v20160927.SingleSendSmsResponse;
import com.engineering.elink.util.ConfigUtil;

public class PhoneSender {
	public static boolean send(String phone, String code) {
		try {
			IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",
					ConfigUtil.getValue("aliyun_app_key_id"),
					ConfigUtil.getValue("aliyun_app_key_secret"));
			DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Sms",
					"sms.aliyuncs.com");
			IAcsClient client = new DefaultAcsClient(profile);
			SingleSendSmsRequest request = new SingleSendSmsRequest();
			request.setSignName("乂联凌工");
			request.setTemplateCode("SMS_33615002");
			request.setParamString("{\"code\":\""+code+"\",\"product\":\"二级\"}");
			request.setRecNum(phone);
			@SuppressWarnings("unused")
			SingleSendSmsResponse httpResponse = client.getAcsResponse(request);
			return true;
		} catch (ServerException e) {
			e.printStackTrace();
		} catch (ClientException e) {
			e.printStackTrace();
		} catch (com.aliyuncs.exceptions.ClientException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}
